<?php
/**
 * jishupu-cms
 * @Author:技术铺<jishupu@qq.com>
 * @Date: 2021/11/11
 */

namespace App\Http\Requests;


use Illuminate\Support\Facades\Auth;

/**
 * 留言咨询模块表单验证
 * Class GuestbookRequest
 * @package App\Http\Requests
 */
class GuestbookRequest extends BaseRequest
{

    /**
     * 注入表单请求验证时自动校验
     *
     * @var bool
     */
    public $autoValidate = false;

    /**
     * 用户是否有权操作，true是，false否
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 字段验证规则
     *
     * @return array
     */
    public function rules()
    {
        return [
            'id' => 'required|integer',
            'created_user_id' => 'required|integer',
            'status' => 'required|boolean',
            'remark' => 'nullable|max:300'
        ];
    }

    /**
     * 提示信息
     * @return array
     */
    public function messages()
    {
        return [
        ];
    }

    /**
     * 定义场景
     * @var \string[][]
     */
    public $scenes = [
        'destroy' => ['id'],
        'updateStatus' => ['remark', 'created_user_id'],
    ];

    /**
     * 验证错误的自定义属性
     *
     * @return array
     */
    public function attributes()
    {
        return [
            'id' => __('common.id'),
            'status' => __('guestbook.status'),
            'remark' => __('common.remark'),
        ];
    }

    /**
     * 验证前
     *
     * @return void
     */
    protected function prepareForValidation()
    {
        $this->offsetSet('created_user_id', Auth::id());
    }
}
